<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    //全局作用域
    let a = 10;
    let c = 40;
    let b = 100;

    function f() {
        //局部作用域
        let a = 20;
        //重新赋值
        b = 30;
        console.log(a, c) //a=20,c=40   a是局部作用域的a  c全局中的c
    }
    f()
    console.log(a, c) //10,40   a是全局作用域的a
    console.log(b) //30(b在函数中重新赋值了)

    //作用域链
    let num = 10;

    function f1() {
        let num = 20;

        function f2() {
            let num = 30;

            function f3() {
                let num = 50;
                //num = 100 如果num=100，等于重新赋值，f3和f2中num为100
                console.log(num) //50
            }
            f3();
            console.log(num) //30
        }
        f2();
        console.log(num) //20
    }
    f1();
    console.log(num) //10
</script>

</html>